// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedBuilding;

import zombie.core.Rand;
import zombie.iso.BuildingDef;
import zombie.iso.IsoCell;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoObject;
import zombie.iso.IsoWorld;

public final class RBSchool extends RandomizedBuildingBase {
    @Override
    public void randomizeBuilding(BuildingDef def) {
        IsoCell isoCell = IsoWorld.instance.CurrentCell;

        for (int int0 = def.x - 1; int0 < def.x2 + 1; int0++) {
            for (int int1 = def.y - 1; int1 < def.y2 + 1; int1++) {
                for (int int2 = 0; int2 < 8; int2++) {
                    IsoGridSquare isoGridSquare = isoCell.getGridSquare(int0, int1, int2);
                    if (isoGridSquare != null && this.roomValid(isoGridSquare)) {
                        for (int int3 = 0; int3 < isoGridSquare.getObjects().size(); int3++) {
                            IsoObject isoObject = isoGridSquare.getObjects().get(int3);
                            if (Rand.NextBool(3) && this.isTableFor3DItems(isoObject, isoGridSquare)) {
                                int int4 = Rand.Next(0, 8);
                                switch (int4) {
                                    case 0:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "Pen", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 1:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "Pencil", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 2:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "Crayons", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 3:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "RedPen", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 4:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "BluePen", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 5:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "Eraser", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                }

                                int int5 = Rand.Next(0, 6);
                                switch (int5) {
                                    case 0:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "Doodle", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 1:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "Book", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 2:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "Notebook", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                        break;
                                    case 3:
                                        isoGridSquare.AddWorldInventoryItem(
                                            "SheetPaper2", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), isoObject.getSurfaceOffsetNoTable() / 96.0F
                                        );
                                }
                            }
                        }

                        if (isoGridSquare.getRoom() != null && "classroom".equals(isoGridSquare.getRoom().getName())) {
                            if (Rand.NextBool(50)) {
                                int int6 = Rand.Next(0, 10);
                                switch (int6) {
                                    case 0:
                                        isoGridSquare.AddWorldInventoryItem("Doodle", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 1:
                                        isoGridSquare.AddWorldInventoryItem("Book", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 2:
                                        isoGridSquare.AddWorldInventoryItem("Notebook", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 3:
                                        isoGridSquare.AddWorldInventoryItem("SheetPaper2", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 4:
                                        isoGridSquare.AddWorldInventoryItem("Pen", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 5:
                                        isoGridSquare.AddWorldInventoryItem("Pencil", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 6:
                                        isoGridSquare.AddWorldInventoryItem("Crayons", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 7:
                                        isoGridSquare.AddWorldInventoryItem("RedPen", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 8:
                                        isoGridSquare.AddWorldInventoryItem("BluePen", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                        break;
                                    case 9:
                                        isoGridSquare.AddWorldInventoryItem("Eraser", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                                }
                            }

                            if (Rand.NextBool(120)) {
                                isoGridSquare.AddWorldInventoryItem("Bag_Schoolbag", Rand.Next(0.4F, 0.8F), Rand.Next(0.4F, 0.8F), 0.0F);
                            }
                        }
                    }
                }
            }
        }
    }

    public boolean roomValid(IsoGridSquare sq) {
        return sq.getRoom() != null && "classroom".equals(sq.getRoom().getName());
    }

    @Override
    public boolean isValid(BuildingDef def, boolean force) {
        return def.getRoom("classroom") != null || force;
    }

    public RBSchool() {
        this.name = "School";
        this.setAlwaysDo(true);
    }
}
